
public class List {


	public List(String[]DataList){
		if(DataList != null){


			for(int i = 0; i<DataList.length; i++){
				add(DataList[i]);
			}
		}

	}

	private class Node {
		public String data;

		public Node next;

		public Node(String data) {
			this.data = data;
		}
	}

	private Node first = null;
	private Node last = null;


	public void add(String info) {
		if (isEmpty()) {
			first = new Node(info);
			last = first;
		} else {
			last.next = new Node(info);
			last = last.next;


		}

		Current = first;
	}


	public String get(int index) {

		// Kontrollera index
		if(index < 0 || index >= size()){
			return null;
		}

		// Normalfallet
		Node temp = first;
		for (; index > 0; index--) {
			temp = temp.next;
		}
		return temp.data;

	}

	public Node Current;


	public String getNext(){

		if(Current == last){
			Current = first;

			return Current.data;
		} else {
			Current = Current.next;
			return Current.data;
		}

	}



	public boolean remove(String info) {
		if(first == null){
			return false;
		}

		if(first.data.equals(info)){
			first = first.next;
			if(first == null){
				last = null;
			}
			return true;
		}

		Node temp = first;

		while(temp.next != null){
			if(temp.next.data.equals(info)){
				Node bort = temp.next;
				temp.next = bort.next;
				if(bort == last){
					last = temp;
				}
				return true;

			} else {
				temp = temp.next;
			}
		}
		return false;
	}


	public int removeAll(String info) {

		int count = 0;
		while(remove(info)){
			count++;
		}
		return count;
	}


	public void clear() {
		first = null;
		last = null;
	}


	public int size() {
		int size = 0;
		Node temp = first;
		while (temp != null) {
			size++;
			temp = temp.next;
		}
		return size;
	}

	public boolean isEmpty() {
		return first == null;

	}



	public String toString() {
		StringBuffer sb = new StringBuffer("[");
		Node temp = first;
		while(temp != null){
			if(temp != first){
				sb.append(",");


			}
			sb.append(temp.data);
			temp = temp.next;
		}
		sb.append("]");
		return sb.toString();
	}
}
